import asyncio
import gui
import os
GUI = gui.GUI()
async def input_massage():
    while True:
        user_name=GUI.input("please input user name:")
        if user_name == "":
            continue
        else:#输入是否失误
            try:
                res=requests.get("https://gitee.com/"+user_name+"/")
                if not res.status_code == 200:
                    GUI.outputcil("please input correct!")
                    continue
                else:
                    break
            except (requests.exceptions.ProxyError,ValueError) as e:
                GUI.outputcil(repr(e))
                GUI.outputcil("please check proxy")
                exit()
    while True:
        GUI.outputcil("please input access_token:")
        access_token = input()
        if user_name == "":
            continue
        else:  # 输入是否失误
            GUI.outputcil("please input access_token again:")
            access_token_again=input()
            if not access_token_again == access_token:
                GUI.outputcil("please input correct!")
                continue
            else:
                break
    return user_name,access_token
async def delete_repo(user_name,access_token,repo):
    while True:
            res=requests.delete(
                "https://gitee.com/api/v5/repos/" + user_name + "/" + repo + "?access_token=" + access_token)
            if not res.status_code == 204:
                GUI.outputcil("please input correct!")
                raise IOError
            else:
                break
    GUI.outputgui("success:"+repo)
def whileinput(user_name, access_token):
    GUI.outputcil("if you want exit,please send exit")
    while True:
        repo = GUI.input("please input repo:")
        if repo == "":
            continue
        elif repo == "exit":
            os._exit(0)
        else:
            try:
                asyncio.run(delete_repo(user_name, access_token, repo))
            except IOError:
                continue
            continue
if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    task = loop.create_task(input_massage())
    import requests
    import threading
    loop.run_until_complete(task)
    (user_name,access_token)=task.result()
    a=threading.Thread(target=whileinput,args=(user_name, access_token,))
    a.setDaemon(True)
    a.start()
    GUI.startgui()